package actions;

import dialogs.AddCategoryDialog;
import views.Category;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.window.Window;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;

//import controller.MainController;

public class AddCategoryAction extends Action implements
		ISelectionListener, IWorkbenchAction {

	private final IWorkbenchWindow window;
	public final static String ID = "is.blogi.actions.AddBlogCategory";
	private Category newCategory;
	
	// bajer na zapameitane zaznaczenie... (str 90)
	// private IStructuredSelection selection;

	public AddCategoryAction(IWorkbenchWindow window) {
		this.window = window;
		setId(ID);
		setText("&Add new category...");
		setToolTipText("Add a new category to organize words.");
		// bajer
		// setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(
		// "org.eclipsercp.hyperbola", IImageKeys.ADD_CONTACT));

		// bajer
		// window.getSelectionService().addSelectionListener(this);
	}

	public void dispose() {
		// bejer
		// window.getSelectionService().removeSelectionListener(this);
	}

	// additional run() and selectionChanged() methods to be added
	// here

	public void run() {
		AddCategoryDialog d = new AddCategoryDialog(window.getShell());
		int code = d.open();
		if (code == Window.OK) {
			newCategory.createCategory(d.getName());
		}
	}

	@Override
	public void selectionChanged(IWorkbenchPart part, ISelection selection) {
		// bajer strona 90

	}

}